package com.lph.niming;

import com.lph.niming.pojo.Case;
import com.lph.niming.service.MyUtils;
import com.lph.niming.service.Myinit;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @auther: Wyz
 * @date: 2021/10/29 19:41
 * @return
 */
public class MyMain {
    //控制台输入函数
    private static Scanner scanner = new Scanner(System.in);

    private static Myinit myinit = new Myinit();

    private static MyUtils myUtils = new MyUtils();

    public static void main(String[] args) {
        //初始数据 list map set
        List<Case> cases = myinit.initCases();
        System.out.println("原始数据为下");
        cases.forEach(s -> System.out.println(s));
        //拿到类中的所有属性
        List<String> attribute = myUtils.getAttribute(new Case());
        System.out.println("此表中所有属性为：" + attribute);
        identification(attribute,cases);
        System.out.println("除去标识符后数据如下");
        cases.forEach(s -> System.out.println(s));
        System.out.println("请输入k值");
        int k = scanner.nextInt();
        //根据k值进行分组
        List<List<Case>> lists = myUtils.averageAssign(cases, cases.size()/k+1);
        //输入准标识符开始匿名
        List<Case> newCases = new ArrayList<>();
        myUtils.quasiIdentification(attribute,lists,newCases);
    }

    public static void identification(List<String> attribute,List<Case> cases) {
        System.out.println("请输入标识属性");
        String next = scanner.next();
        switch (next) {
            case ("id"):
                //删除类中的字段
                myUtils.deleteField(attribute, next,cases);
                //删除这个字段后把这个字段全部值赋值为null
                cases.forEach(c->c.setId(null));
                break;
            case ("age"):
                myUtils.deleteField(attribute, next,cases);
                cases.forEach(c->c.setAge(null));
                break;
            case ("name"):
                myUtils.deleteField(attribute, next,cases);
                cases.forEach(c->c.setName(null));
                break;
            case ("zipCode"):
                myUtils.deleteField(attribute, next,cases);
                cases.forEach(c->c.setZipCode(null));
                break;
            case ("phone"):
                myUtils.deleteField(attribute, next,cases);
                cases.forEach(c->c.setPhone(null));
                break;
            case ("sex"):
                myUtils.deleteField(attribute, next,cases);
                cases.forEach(c->c.setSex(null));
                break;
            case ("healthState"):
                myUtils.deleteField(attribute, next,cases);
                cases.forEach(c->c.setHealthState(null));
                break;
            default:
                System.out.println("请输入正确的字段名：" + attribute);
                identification(attribute,cases);
                break;
        }
    }


}
